Robotics 1.0
Lesson 14: Let's Sense - Obstacle Avoiding Rover.

Purpose: Use an ultrasonic sensor with the CPX and Crickit board to detect obstacles and program the bot to navigate while avoiding them.

No. of. Classes

1 - 1 (Time : 1 hour and 30 minutes, each group has a maximum of 4 students).

Materials Required
  • CPX(Arduino board), Crickit and USB cable

  • Acrylic chassis kit

  • Ultrasonic sensor

  • Jumper wires

  • Rechargeable batteries

  • Foam board and object to place for obstacles

Prior knowledge

Students should already know how to connect and control DC motors through the Crickit and CPX. They should understand basic rover movement using code and how sensors provide input signals.

Exercises

Exercise 1



Setting up the ultrasonic sensor


  • Connecting the ultrasonic sensor

    Click here to view the instructions for connecting the Ultra sonic sensor to the crickit board and learn more on the working of the ultrasonic sensor


    Ultrasonic Sensor Working

  • Reading the values of the ultrasonic sensor

    Print the raw distance values using the instructions and code in this document



  • Exercise 2



    Build the obstacle detecting rover


  • Fix the ultrasonic sensor on the rover

    Use this video and fix the ultra sonic sensor to detect obstacles in front of the rover and a servo with an arm to push them away

  • Click here to view the pseudocode and implement the code logic for avoiding or pushing away obstacles while also navigating the lines.
  • Solution



  • Click here to view the solution video for Exercise 2.
  • Click here to view the code and explanation for Exercise 2.
  • Teacher's Instruction
    1. Introduce the ultrasonic sensor and explain how it measures distance using sound waves, including how the trigger and echo signals work.
    2. Explain situations where IR sensors may fail, such as dark surfaces or bright light, and why ultrasonic sensors are more reliable for measuring distance.
    3. Demonstrate how to connect the ultrasonic sensor to the CPX and Crickit board.
    4. Walk through a simple CircuitPython program to read distance values and print them for testing.
    5. Introduce the flowchart diagram for obstacle avoidance and explain how the decision-making logic works step by step.
    6. Explain the concept of state tracking and why we track the rover’s movement state instead of calling motor functions repeatedly.
    7. Guide students to implement obstacle avoidance logic using distance thresholds and controlled motor actions.
    8. Conclude by reinforcing that sensors provide input, logic makes decisions, and motors act as output devices.
    9. Discuss about the different variants of the ultrasonic sensor like HC-SR04 or the US-100 and why we chose the US-100 (It has default support with Adafruit libraries)
    10. Why do you think we use an ultrasonic sensor for measuring distance even though an IR sensor can also detect objects and in what situations might one work better than the other?